#include "ccd290.h"

int main( int argc, char *argv[] ){

	char bin_file[1024];
	char cfg_file[1024];
	int has_cfg = 0;
	int has_bin = 0;
	
	int has_outfile_opt = 0;
	char outfile[1024];
	
	int has_os_num_opt = 0;
	int os_num = -1;

//	命令行参数处理
	int opt;
	while( (opt = getopt(argc,argv,"b:c:n:o:")) != -1 ){
		switch(opt){
			case 'b':
				has_bin = 1;
				sprintf(bin_file, "%s", optarg);
				break;
			case 'c':
				has_cfg = 1;
				sprintf(cfg_file, "%s", optarg);
				break;
			case 'n':
			    has_os_num_opt = 1;
			    os_num = atoi(optarg);
			    break;
			case 'o':
			    has_outfile_opt = 1;
			    sprintf(outfile, "%s", optarg);
			    break;
			default:
				printf("other option: %c\n", opt);
		}
	}


	if( has_cfg == 0 || has_bin == 0 ){
		printf(" usage:\n\t%s -c wf_cfg.ini -b wave.bin -o out_os.txt\n", argv[0]);
		return 0;
	}

	waveform_config wf_cfg;

	init_waveform_config( &wf_cfg, cfg_file );
	
	//  update config
	if( has_os_num_opt == 1 ){
	    wf_cfg.OS_NUM = os_num;
	}
	
	if( has_outfile_opt == 1 ){
	    sprintf(wf_cfg.outfile,"%s", outfile);
	} else {
	    sprintf(wf_cfg.outfile,"");
	}

	extract_waveform( &wf_cfg, bin_file );

	return 0;
}
